package com.atguigu.principle.inversion.improve;

/**
 * @author ccc
 * @create 2020-07-09 15:22
 */
public class DependencyPassOfConstructor{
    public static void main(String[] args) {
        ITV2 TV2 = new ChangHongTV2(); //电视实例

        //通过构造器进行依赖的传递
        OpenAndClose2 openAndClose2 = new OpenAndClose2(TV2);
        openAndClose2.open();
    }
}

//方式2 通过构造器传递依赖
//开关的接口
interface IOpenAndClose2{
    public void open(); //抽象方法，接收接口
}

interface ITV2 { //ITV 接口 用来搞具体电视类型 长虹之类的
    public void play();
}

//实现接口
class OpenAndClose2 implements IOpenAndClose2{
    public ITV2 tv2; //将接口作为成员
    public OpenAndClose2(ITV2 tv2){//构造器
        this.tv2 = tv2;
    }
    @Override
    public void open() {
        this.tv2.play();
    }
}

class ChangHongTV2 implements ITV2{ //使用长虹电视来举例

    @Override
    public void play() {
        System.out.println("长虹电视开机");
    }
}